<template>
	<view class="poRel minH100vC100r boSiBorBox">
		<view class="poAbs wPer100 hPer100 backColrgba255a255a255a0s9 top0 left0 zIndex1"
			v-if="!token"
		>
			<navigator class="w300r teAliCenter backCol64aeb4 lh80r colFff borRad40r poAbs top50P left50P trTrn50Pn50P"
				url="/pages/personalCenter/login"
			>
				立即登录
			</navigator>
		</view>
		<view class="borB1SE6e6e6 h80r aliItCenter backColWhite disFlex pl24r pr24r">
			<view class="flex1 col292929">
				<picker mode="date" :value="data0Date1" :start="startDate" :end="endDate"
					@change="data0bindDateChange1"
				>
					<view class="wPer95 h60r lh60r borRad30r bor1SCcc teAliCenter">
						{{data0Date1}}
					</view>
				</picker>
			</view>
			<view class="w140r teAliCenter poRel">
				<view class="w120r bor1S99c043 floRight lh50r borRad25r col99c043"
					@click="cliScreen"
				>
					筛选
				</view>
			</view>
		</view>
		<view class="p20r">
			<view class="mb40r backColWhite borRad10r"
				v-for="item1 in roomList" :key="item1.id"
			>
				<view class="p20r backImgLiGrTRE5e7fcaFff disFlex aliItCenter">
					<view class="flex1 foWeiBold">
						{{item1.name}}
					</view>
					<view class="w230r teAliRight">
						<text class="w100r lh46r disInBlo teAliCenter bor1S67c23a col67c23a borRad25r mr10r"
							@click="cliCircuitBreaker1(item1.id)"
						>
							断路器
						</text>
						<text class="w100r lh46r disInBlo teAliCenter bor1SE6a23c colE6a23c borRad25r"
							@click="cliOpenDoor(item1.id)"
						>
							开门
						</text>
					</view>
				</view>
				<view class="teAliCenter lh100r col999" v-if="item1.order_list.length == 0">
					这一天没有订单
				</view>
				<view class="pl20r pr20r"
					v-if="item1.order_list && item1.order_list.length"
				>
					<view :class="['disFlex', 'pt20r', 'pb20r',
							index2 == (item1.order_list.length - 1) ? '' : 'borB1SE6e6e6'
						]"
						v-for="(item2, index2) in item1.order_list" :key="index2"
					>
						<view class="w50r lh50r">
							<text class="foWeiBold">
								{{(index2 + 1) + '.'}}
							</text>
						</view>
						<view class="flex1">
							<view class="lh50r">
								<text class="col999">
									开始时间：
								</text>
								{{item2.start_time}}
							</view>
							<view class="lh50r">
								<text class="col999">
									结束时间：
								</text>
								{{item2.end_time}}
							</view>
							<view class="lh50r col999" v-if="item2.is_top_order_status == 1">
								请于
								<text class="foWeiBold col363636">
									{{item2.clear_end_time}}
								</text>
								前完成保洁
							</view>
							<view class="lh50r foWeiBold col363636" v-if="item2.is_top_order_status == 2">
								被续单
							</view>
							<view class="disFlex">
								<view :class="['lh50r', 'foWeiBold', 'flex1',
										item2.make_status == 3 ? 'col00c260' : 'colC72d21'
									]"
								>
									<text class="col999 foWeiNor">
										订单状态：
									</text>
									{{
										item2.make_status == 1 ? '待使用' :
										item2.make_status == 2 ? '使用中' :
										item2.make_status == 3 ? '已完成' :
										item2.make_status == 4 ? '已取消' : item2.make_status
									}}
								</view>
							</view>
							<view class="disFlex">
								<view :class="['lh50r', 'foWeiBold', 'flex1',
										item2.is_release == 2 ? 'col00c260' : 'colC72d21'
									]"
								>
									<text class="col999 foWeiNor">
										释放状态：
									</text>
									{{
										item2.is_release == 1 ? '未释放' :
										item2.is_release == 2 ? '已释放' : item2.is_release
									}}
								</view>
								<view class="flex1 teAliRight">
									<text class="w140r lh50r disInBlo teAliCenter ml10r boSiBorBox bor1S4d76f4 col3579f7 borRad10r"
										v-if="item2.type == 2 && item2.is_release == 1 && item2.make_status == 3"
										@click="cliManualRelease(item2.rid, item2.out_trade_no)"
									>
										手动释放
									</text>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="col999 teAliCenter lh60r" v-if="roomList.length">
				已加载全部
			</view>
		</view>
	</view>
</template>
<script>
import { inquiryToLogin, dateLimit } from '@/utils/utils.js'
import { cleanGetTeaRoomList, isTeaRoomReleaseTime,
	cleanOpenDoor, cleanOpenSwitch } from '@/utils/api.js'
export default {
	data() {
		return {
			token: '',
			data0Date1: '',
			roomList: []
		}
	},
	computed: {
		startDate() {
			return dateLimit('oldYear1');
		},
		endDate() {
			return dateLimit('start');
		}
	},
	onShow() {
		this.data0Date1 = dateLimit();
		const token = uni.getStorageSync('token');
		if(token) {//此项目中这种写法是弹遮罩层按钮点击跳登录页
			this.token = token;
			this.getDataList1();
		}else {
			this.token = '';
			this.roomList = [];
		}
	},
	methods: {
		getDataList1() {
			this.roomList = [];
			cleanGetTeaRoomList({
				token: this.token, date: this.data0Date1
			}).then(res => {
				if(res.data && res.data.length) {
					res.data.forEach(item1 => {
						if(item1.type === '1') {
							this.roomList.push(item1)
						}
					})
				}
			})
		},
		data0bindDateChange1(eee) {
			this.data0Date1 = eee.detail.value
		},
		cliScreen() {
			this.getDataList1();
		},
		cliCircuitBreaker1(rid) {
			uni.showActionSheet({
				itemList: ['开启断路器', '关闭断路器'],
				success:res1 => {
					if(res1.tapIndex == 0) {
						console.log(11)
						this.cliCircuitBreaker2(rid, 1);
					}else if(res1.tapIndex == 1) {
						console.log(22)
						this.cliCircuitBreaker2(rid, 2);
					}
				}
			})
		},
		cliCircuitBreaker2(rid, type) {
			cleanOpenSwitch({
				token: this.token, rid, type
			}).then(res1 => {
				uni.showToast({
					title: `${type == 1 ? '开启' : '关闭'}成功`, duration: 3000
				})
			})
		},
		cliOpenDoor(rid) {
			uni.showModal({
				title: '提示', content: '确定开门？', confirmColor: '#99c043',
				success:res1 => {
					if (res1.confirm) {
						cleanOpenDoor({
							token: this.token, rid
						}).then(res2 => {
							uni.showToast({
								title: '开门成功', duration: 3000
							})
						})
					}
				}
			})
		},
		cliManualRelease(rid, out_trade_no) {
			uni.showModal({
				title: '提示', content: '确定手动释放这条订单？', confirmColor: '#99c043',
				success:res1 => {
					if (res1.confirm) {
						isTeaRoomReleaseTime({
							token: this.token, rid, out_trade_no
						}).then(res2 => {
							this.getDataList1();
							uni.showToast({
								title: '手动释放成功', duration: 3000
							})
						})
					}
				}
			})
		}
	}
}
</script>
<style>
</style>